define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/fleet/cteamOrderInfos/support", "AppPathDir/fleet/cteamOrderInfos/update", "AppPathDir/fleet/cteamOrderInfos/reserve", "AppPathDir/fleet/cteamOrderInfos/agree", "PDUtilDir/util",
						"PDUtilDir/tool", "PDUtilDir/slidebar",
						"PDUtilDir/inputSelect", "Date", "DateCN", "css!DateCss"],
				function(Support, UpdateSupport, ReserveInfoSupport, AgreeSupport, Util, Tool, Slidebar, inputSelect) {
                    $scope.cache = {
                        type : new Array(),
                        typeMap: new Map(),
                        status : new Array(),
                        statuMap: new Map(),
                        payStatus : new Array(),
                        payStatuMap: new Map()
                        // provinces : new Array()
                    };
                    $scope.search = {};

					/* 查询 start */
					$scope.searchSupport = {
						run: function(){
							$scope.grid.reload({
                                queryParam : {
                                    model: JSON.stringify($scope.search)
                                }
							})
						}
					};

                    /* 拒绝 */
                    $scope.refuseSupport = {
                        run : function(id) {
                            Util.confirm("是否拒绝", function() {
                                $.ajax({
                                    url : getServer() + "/flea/hclv/car/reserve/updateReserveStatus.htmls",
                                    data : {
                                        model : JSON.stringify({
                                            id: id,reserveStatus: 'D_CAR_RESERVE_STATUS_NO'
                                        })
                                    },
                                    success : function(data) {
                                        if (data.status != 200) {
                                            return;
                                        }
                                        Util.alert(data.message);
                                        $scope.grid.refresh();
                                    }
                                });
                            })
                        }
                    };


                    /* 同意 */
                    $scope.agreeSupport = AgreeSupport($scope, $compile);

                    //详情
                    $scope.reserveInfoSupport = ReserveInfoSupport($scope, $compile);

                    //修单
                    $scope.updateSupport = UpdateSupport($scope, $compile);

                    //状态列表
                    $.ajax({
                        url : getServer() + "/flea/hclv/getCarReserveStatus.htmls",
                        success : function(data) {
                            if (data.status != 200) {
                                return;
                            }
                            $scope.cache.status = data.data;
                            $.each(data.data, function(index, row) {
                                $scope.cache.statuMap.set(row.dictCode, row.dictName);
                            });
                            init();
                        }
                    });
                    //车辆类型
                    $.ajax({
                        url : getServer() + "/flea/hclv/getVehicle.htmls",
                        success : function(data) {
                            $scope.cache.type = data.data;
                            $.each(data.data, function(index, row) {
								$scope.cache.typeMap.set(row.dictCode, row.dictName);
							});
                            init();
                        }
                    });
                    //支付状态列表
                    $.ajax({
                        url : getServer() + "/flea/hclv/getCarReservePayStatus.htmls",
                        success : function(data) {
                            if (data.status != 200) {
                                return;
                            }
                            $scope.cache.payStatus = data.data;
                            $.each(data.data, function(index, row) {
                                $scope.cache.payStatuMap.set(row.dictCode, row.dictName);
                            });
                            init();
                        }
                    });
					var init = function(){
						if($scope.cache.type.length > 0 && $scope.cache.status.length > 0 && $scope.cache.payStatus.length > 0) {
                            $scope.grid = Support.init($scope.cache, $scope.reserveInfoSupport, $scope.searchSupport);
                            //订单状态
                            inputSelect.dropCache();
                            inputSelect({
                                id: "statusInput",
                                key: {
                                    id: "dictCode",
                                    name: "dictName",
                                    data: "data",
                                },
                                data: $scope.cache.status,
                                simpleData: true,
                                searchAble: false,
                                callback: function (id) {
                                    $scope.search.reserveStatus = id[0];
                                }
                            });
                        }
					}
				})
	}
});